<script>
import { login } from '@/http/api'
import { mapState, mapMutations } from 'vuex'
import { SET_OPEN_ID } from './store/mutation-types'
import '../static/css/colorui.wxss'
import '../static/css/icon.wxss'
const App = getApp()
export default {
  data: {
    globalData: {}
  },
  computed: {
    ...mapState(['openId'])
  },
  methods: {
    ...mapMutations({ setOpenId: 'SET_OPEN_ID' }),
    async login (code) {
      let _this = this
      try {
        const resData = await login({ code: code })
        if ((resData.statusCode == 200)) {
          // _this.setOpenId(resData.data.accountId);
          _this.globalData.token = resData.data.usertoken
          wx.setStorageSync('token', resData.data.usertoken)
        }
      } catch (err) {
        console.error(err)
      }
    },
    _login () {
      let _this = this
      wx.login({
        success (res) {
          if (res.code) {
            console.log('wx.login成功,code:', res.code)
            let code = res.code
            _this.login(code)
          } else {
            _this.$tips.toast('微信登录失败')
          }
        }
      })
    }
  },
  created () {
    this._login()
  }
}
</script>

<style lang="scss">
.fl {
  float: left;
}
.fr {
  float: right;
}
.mt20{margin-top:20rpx;margin-left: 20rpx;}
.hi40{height:40rpx;}
.copyright{
    margin-top:20rpx;
    background:#fff;
    font-size: 13px;
    letter-spacing: .3px;
    color: #808080;
    text-align:center;
    padding:40rpx 0;
}
</style>
